/**
 * 
 */
package org.apache.struts.register.action;

import org.apache.struts.register.model.Person;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @author wanghy
 * @since 2014-2-26
 * 
 */
public class Register extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Person personBean;

	@Override
	public String execute() throws Exception {

		return SUCCESS;
	}

	public void validate() {

		if (personBean.getFirstName().length() == 0) {
			addFieldError("personBean.firstName", "First name is required.");
		}

		if (personBean.getEmail().length() == 0) {
			addFieldError("personBean.email", "Email is required.");
		}

		if (personBean.getAge() < 18) {
			addFieldError("personBean.age",
					"Age is required and must be 18 or older");
		}

	}

	/**
	 * @return the personBean
	 */
	public Person getPersonBean() {
		return personBean;
	}

	/**
	 * @param personBean
	 *            the personBean to set
	 */
	public void setPersonBean(Person personBean) {
		this.personBean = personBean;
	}

}
